<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
    <input type="hidden" name="row[shop_no]" value="{$ids}">
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">图片:</label>
        <div class="col-xs-12 col-sm-8">
            <div class="input-group">
                <input id="c-img" data-rule="required" class="form-control" size="50" name="row[img]" type="text" value="">
                <div class="input-group-addon no-border no-padding">
                    <span><button type="button" id="faupload-img" class="btn btn-danger faupload" data-input-id="c-img" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp,image/webp" data-multiple="false" data-preview-id="p-img"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
                    <span><button type="button" id="fachoose-img" class="btn btn-primary fachoose" data-input-id="c-img" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
                </div>
                <span class="msg-box n-right" for="c-img"></span>
            </div>
            <ul class="row list-inline faupload-preview" id="p-img"></ul>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
        <div class="col-xs-12 col-sm-8">
            
            <div class="radio">
            <label for="row[status]"><input id="row[status]" name="row[status]" type="radio" value="1" checked />正常</label> 
            </div>

        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">活动:</label>
        <div class="col-xs-12 col-sm-10" style="height: 300px;overflow-y: auto;">
            <table class="table table-striped table-bordered table-hover table-nowrap" id="table">
                <thead>
                    <tr>
                        <th class="bs-checkbox " data-field="state">
                            <div class="th-inner "><input id="btSelectAll" name="btSelectAll" type="checkbox"></div>
                            <div class="fht-cell"></div>
                        </th>
                        <th class="word-position">
                            <div class="th-inner ">外卖单编号</div>
                        </th>
                        <th class="word-position">
                            <div class="th-inner ">下单时间</div>
                        </th>
                        <th class="word-position">
                            <div class="th-inner ">应付金额</div>
                        </th>
                        <th class="word-position">
                            <div class="th-inner ">平台手续费</div>
                        </th>
                        <th class="word-position">
                            <div class="th-inner ">用户收入</div>
                        </th>
                        <th class="word-position">
                            <div class="th-inner ">订单状态</div>
                        </th>
                        <th class="word-position">
                            <div class="th-inner ">支付状态</div>
                        </th>
                    </tr>
                </thead>
                <tbody>
                {foreach $play as $p}
                    <tr>
                        <td class="bs-checkbox ">
                            <input data-index="{$p.id}" name="btSelectItem[]" type="checkbox" value="{$p.id}">
                        </td>
                        <td class="word-position">{$p.wm_order_sn}</td>
                        <td class="word-position">{$p.place_time}</td>
                        <td class="word-position">{$p.rebate_amt}</td>
                        <td class="word-position">{$p.service_charge_amt}</td>
                        <td class="word-position">{$p.actual_rebate_amt}</td>
                        <td class="word-position">{$p.order_status_text}</td>
                        <td class="word-position">{$p.is_pay_text}</td>
                    </tr>
                {/foreach}
                </tbody>
            </table>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">选择日期:</label>
        <div class="col-xs-12 col-sm-8">
            <input type="text" class="form-control datetimerange" data-time-picker="false" placeholder="订单日期" name="row[date_range]" date-show-dropdowns="true" value="" autocomplete="off" id="date_range" /> 
        </div>
        <input type="button" id="search" name="button" value="筛选" class="btn btn-success btn-embossed">
    </div>
    <div class="form-group" id="sumdiv">
        <label class="control-label col-xs-12 col-sm-2">支付金额:</label>
        <div class="col-xs-12 col-sm-8" id="sum" style="padding-top: 7px;">0.00
        </div>
    </div>
    <div class="form-group layer-footer">
        <label class="control-label col-xs-12 col-sm-2"></label>
        <div class="col-xs-12 col-sm-8">
            <button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
        </div>
    </div>
</form>
<script type="text/javascript" src="https://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
    // 全选
    $(document).on('click', "#btSelectAll", function () {
        $('#sum').text('计算中...')
        var sum=0
        var item=0
        if ($(this).is(":checked")) {
            $("#table input[name='btSelectItem[]']").each(function (i,j) {
                if (!$("#table input[name='btSelectItem[]']").eq(i).parents('tr').is(':hidden')) {
                    $("#table input[name='btSelectItem[]']").eq(i).prop("checked", true);
                    item=$("#table tbody tr").eq(i).find('.word-position').eq(2).text()
                    item=parseFloat(item).toFixed(2)
                    sum=sum+parseFloat(item)
                    console.log(sum)
                } else {
                    $("#table input[name='btSelectItem[]']").eq(i).prop("checked", false);
                }
            })
        } else {
            $("#table input[name='btSelectItem[]']").prop("checked", false);
        }
        $('#sum').text(sum.toFixed(2))
    });
    $(document).on('click', "input[name='btSelectItem[]']", function () {
        $('#sum').text('计算中...')
        var sum=0
        var item=0
        $("#table input[name='btSelectItem[]']").each(function (i,j) {
            if ($("#table input[name='btSelectItem[]']").eq(i).is(":checked")) {
                item=$("#table tbody tr").eq(i).find('.word-position').eq(2).text()
                item=parseFloat(item).toFixed(2)
                sum+=parseFloat(item)
            }
        })
        $('#sum').text(sum.toFixed(2))
    })
    $('#search').click(function () {
        var date_range=$('#date_range').val()
        if (date_range.length==0) {
            alert('请选择时间')
        }
        $.ajax({
            url: "shops/middleman/order",
            type: 'post',
            dataType: 'json',
            data: {date: date_range},
            success: function (ret) {
                if (ret.code==0) {
                    alert(ret.msg)
                } else {
                    var length=ret.data.play_order.length
                    var html =''
                    for (var i = length - 1; i >= 0; i--) {
                        html += '<tr><td class="bs-checkbox "><input data-index="'+ret.data.play_order[i].id+'" name="btSelectItem[]" type="checkbox" value="'+ret.data.play_order[i].id+'"></td>'
                        html += '<td class="word-position">'+ret.data.play_order[i].wm_order_sn+'</td>'
                        html += '<td class="word-position">'+ret.data.play_order[i].place_time+'</td>'
                        html += '<td class="word-position">'+ret.data.play_order[i].rebate_amt+'</td>'
                        html += '<td class="word-position">'+ret.data.play_order[i].service_charge_amt+'</td>'
                        html += '<td class="word-position">'+ret.data.play_order[i].actual_rebate_amt+'</td>'
                        html += '<td class="word-position">'+ret.data.play_order[i].order_status_text+'</td>'
                        html += '<td class="word-position">'+ret.data.play_order[i].is_pay_text+'</td></tr>'
                    }
                    $('#table tbody').html(html)
                    // $('#sum').html(ret.data.sum)
                }
            }, error: function (e) {
                alert('请求出错');
            }
        });
    })
</script>
